{
 "nbformat": 4,
 "nbformat_minor": 2,
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "version": "3.7.6-final"
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3,
  "kernelspec": {
   "name": "python37664bite03da1039dda4451a99dcac6d7e75e79",
   "display_name": "Python 3.7.6 64-bit"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# save()模块中\n",
    "try:\n",
    "    students_txt = open(filename, 'a') # 以追加模式打开\n",
    "except Exception as e:\n",
    "    students_txt = open(filename, 'w') # 以写模式打开\n",
    "\n",
    "\"\"\"\n",
    "1. 'w'写模式打开，若文件不存在则就会创建——注意：每次写入的时候都会清空原信息\n",
    "2. 'a'追加模式，会保留文件中原来的信息\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "str(d) # 字典转化为字符串\n",
    "eval(alist) # 将保存字典的字符串转化为字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if name == '': # 表示name没有输入\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "if __name__ = '__main__':\n",
    "    pass\n",
    "\n",
    "if __name__ = '__main__':\n",
    "    main()\n",
    "\"\"\"\n",
    "1. 当有这段代码的.py文件被直接运行的时候，该代码块将被运行\n",
    "2. 当这段代码的.py文件被以模块的形式导入时，该文件本身不被运行\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"查询模块首先要判断文件是否存在\"\"\"\n",
    "if os.path.exists(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f.readlines() # 换行读取全部文件\n",
    "student_list.clear() # 清空列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "SyntaxError:unexpected EOF while parsing\n",
    "\"\"\"解析时遇到了EOF错误\n",
    "   错误原因：存储的文件中有了很多空白\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"找到要修改的学生信息时，用循环进行输入信息，这样为了避免输入错误还可以重新输入\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for alist in student_all:\n",
    "    print(str(alist), end='') # 消除换行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "student_new.sort(key=lambda x:x[1], reverse=True)\n",
    "\"\"\"列表排序的时候，采用匿名函数\"\"\""
   ]
  }
 ]
}